function newclasslink_clicked()
{
	//$("#newclasslink").addClass("hideA");
	$("#hidenewclasslink").removeClass("hideA");
	$("#divNewClass").find("#newClassMessage").html('');
	$("#divNewClass").removeClass("hideDiv");
	}
function hidenewclasslink_clicked()
{
	$("#newclasslink").removeClass("hideA");
	$("#hidenewclasslink").addClass("hideA");
	$("#divNewClass").addClass("hideDiv");
	}
function viewclasslink_clicked()
{
	//$("#viewclasslink").addClass("hideA");
	$("#hideviewclasslink").removeClass("hideA");
	$("#divViewClass").find("#viewClassMessage").html('');
	$("#divViewClass").removeClass("hideDiv");
	}
function hideviewclasslink_clicked()
{
	$("#viewclasslink").removeClass("hideA");
	$("#hideviewclasslink").addClass("hideA");
	$("#divViewClass").addClass("hideDiv");
	}
function AddClass()
{
	$("#divNewClass").find("#newClassMessage").html('');//clear message
	var className=$("#txbClassName").val()
	className=$.trim(className)
	if(className=='')
		$("#divNewClass").find("#newClassMessage").html('*班级名字不能为空！')
	else
		{
			$.ajax({
            type: 'Post',
            url: '/mngclass_action_add',
            data: "className="+className,
            success: function(response) {
                alert(response);
            	}
        	})	
		}
}
function resolveMessage(msg)
{
	if(msg=='failed')
	 alert('系统原因，添加失败。')
	else if(msg=='add succeed')
	 alert('添加成功！')
	else if(msg=='same class')
	 alert('当前班级名字已经存在，添加失败！')
}

function SearchClass()
{
	$("#divViewClass").find("#viewClassMessage").html('');//clear message
	var className=$("#txbSearchClassName").val()
	className=$.trim(className)
	$.ajax({
            type: 'Post',
            url: '/mngclass_action_search',
            data: "className="+className,
			dataType:"json",
            success: function(response) {
                resolveMessage(response);
            	}
        	})	
}

function resolveMessage(msg)
{
	$('#txbSearchClassName').val("");
	if(msg=='failed')
	 alert('系统原因，查询失败。')
	else
	 BuildUpTable(msg)
}
function BuildUpTable(data)
{
	$("#mngclass_table").find("tr[id!='header']&&[id!='template']").remove();
	var table=$("#mngclass_table")
	$(data).each(function(i){
			var row = $("#mngclass_table").find('#template').clone();
			
			$(row).find("#classTd").find("div").html(this.className);
			$(row).find("#classActiveTd").text(this.isActiveClass);
			$(row).attr("id","ready");
			$(row).removeClass("hiddenTd");
			if(i%2==0)
			{
				$(row).addClass("colorTr");
				}
            row.appendTo(table);
			})
}
function classDelete_clicked(sender)
{
	var tr=$(sender).parent().parent();
	className=$(tr).find("#classTd").find('div').html();
	$.ajax({
            type: 'Post',
            url: '/mngclass_action_delete',
            data: "className="+className,
            success: function(response) {
                if(response=='failed')
	 				alert('系统原因，删除失败。')
				else
				{
					alert('成功删除班级')
					SearchClass();
				}
            }
        })
}

function classActive_clicked(sender)
{
	var tr=$(sender).parent().parent();
	className=$(tr).find("#classTd").find('div').html();
	$.ajax({
            type: 'Post',
            url: '/mngclass_action_active',
            data: "className="+className,
            success: function(response) {
                if(response=='failed')
	 				alert('系统原因，激活失败。')
				else
				{
					alert('成功激活班级')
					SearchClass();
				}
            }
        })
}